home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / Kubuntu 8.10 / kubuntu-8.10-desktop-i386.iso / casper / filesystem.squashfs / usr / share / hplip / ui / scrollunload.py < prev    next >
Text File  |  2008-10-13  |  23KB  |  652 lines

  1. # -*- coding: utf-8 -*-
  2. #
  3. # (c) Copyright 2001-2007 Hewlett-Packard Development Company, L.P.
  4. #
  5. # This program is free software; you can redistribute it and/or modify
  6. # it under the terms of the GNU General Public License as published by
  7. # the Free Software Foundation; either version 2 of the License, or
  8. # (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program; if not, write to the Free Software
  17. # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
  18. #
  19. # Author: Don Welch
  20. #
  21.  
  22. # Local
  23. from base.g import *
  24. from base import utils, magic
  25. from pcard import photocard
  26. from ui_utils import load_pixmap
  27.  
  28. # Qt
  29. from qt import *
  30. from scrollview import ScrollView, PixmapLabelButton
  31. from imagepropertiesdlg import ImagePropertiesDlg
  32. #from waitform import WaitForm
  33.  
  34. # Std Lib
  35. import os.path, os
  36.  
  37. class IconViewItem(QIconViewItem):
  38.     def __init__(self, parent, dirname, fname, path, pixmap, mime_type, mime_subtype, size, exif_info={}):
  39.         QIconViewItem.__init__(self, parent, fname, pixmap)
  40.         self.mime_type = mime_type
  41.         self.mime_subtype = mime_subtype
  42.         self.path = path
  43.         self.dirname = dirname
  44.         self.filename = fname
  45.         self.exif_info = exif_info
  46.         self.size = size
  47.         self.thumbnail_set = False
  48.  
  49.  
  50. class ScrollUnloadView(ScrollView):
  51.     def __init__(self, service, parent=None, form=None, name=None, fl=0):
  52.         ScrollView.__init__(self, service, parent, name, fl)
  53.         
  54.         self.form = form
  55.         self.progress_dlg = None
  56.         self.unload_dir = os.path.normpath(os.path.expanduser('~'))
  57.  
  58.         self.image_icon_map = {'tiff' : 'tif',
  59.                                'bmp'  : 'bmp',
  60.                                'jpeg' : 'jpg',
  61.                                'gif'  : 'gif',
  62.                                'unknown' : 'unknown',
  63.                                 }
  64.  
  65.         self.video_icon_map = {'unknown' : 'movie',
  66.                                 'mpeg'    : 'mpg',
  67.                                 }
  68.  
  69.         QTimer.singleShot(0, self.fillControls)
  70.  
  71.  
  72.     def fillControls(self):
  73.         ScrollView.fillControls(self)
  74.  
  75.         if 0:
  76.             self.addGroupHeading("error", self.__tr("ERROR: Photo Card Failed to Mount Properly. Please check device and card and try again."))
  77.  
  78.         self.addGroupHeading("files_to_unload", self.__tr("Select File(s) to Unload from Photo Card"))
  79.         self.addIconList()
  80.  
  81.         self.addGroupHeading("folder", self.__tr("Unload Folder"))
  82.         self.addFolder()
  83.  
  84.         self.removal_option = 1 # remove files (default)
  85.  
  86.         self.addGroupHeading("options", self.__tr("Unload Options"))
  87.         self.addOptions()
  88.  
  89.         self.addGroupHeading("space1", "")
  90.  
  91.         self.unloadButton = self.addActionButton("bottom_nav", self.__tr("Unload File(s)"), 
  92.                                 self.unloadButton_clicked, 'download.png', 'download-disabled.png', 
  93.                                 self.__tr("Close"), self.funcButton_clicked)
  94.  
  95.         self.unloadButton.setEnabled(False)
  96.  
  97.         self.maximizeControl()   
  98.  
  99.  
  100.     def onDeviceChange(self, cur_device=None):
  101.         if cur_device is not None:
  102.             log.debug("ScrollUnloadView.onDeviceChange(%s)" % cur_device.device_uri)
  103.             self.cur_device = cur_device
  104.         else:
  105.             log.debug("ScrollUnloadView.onDeviceChange(None)")
  106.  
  107.         # TODO: Print a message telling users to use USB mass storage if possible
  108.         QTimer.singleShot(0, self.mountCard)
  109.  
  110.  
  111.     def mountCard(self):
  112.         self.pc = None
  113.  
  114.         if self.cur_device is not None and self.cur_device.supported:
  115.  
  116.             QApplication.setOverrideCursor(QApplication.waitCursor)
  117.  
  118.             try:
  119.                 self.pc = photocard.PhotoCard(None, self.cur_device.device_uri, self.cur_printer)
  120.             except Error, e:
  121.                 QApplication.restoreOverrideCursor()
  122.                 self.form.FailureUI(self.__tr("An error occured: %s" % e[0]))
  123.                 self.cleanup(EVENT_PCARD_UNABLE_TO_MOUNT)
  124.                 return False
  125.  
  126.             if self.pc.device.device_uri is None and self.cur_printer:
  127.                 QApplication.restoreOverrideCursor()
  128.                 self.form.FailureUI(self.__tr("Printer '%s' not found." % self.cur_printer))
  129.                 self.cleanup(EVENT_PCARD_JOB_FAIL)
  130.                 return False
  131.  
  132.             if self.pc.device.device_uri is None and self.cur_device.device_uri:
  133.                 QApplication.restoreOverrideCursor()
  134.                 self.form.FailureUI(self.__tr("Malformed/invalid device-uri: %s" % self.device_uri))
  135.                 self.cleanup(EVENT_PCARD_JOB_FAIL)
  136.  
  137.                 return False
  138.             else:
  139.                 try:
  140.                     self.pc.mount()
  141.                 except Error:
  142.                     QApplication.restoreOverrideCursor()
  143.                     self.form.FailureUI(self.__tr("<b>Unable to mount photo card on device.</b><p>Check that device is powered on and photo card is correctly inserted."))
  144.                     #self.pc.umount()
  145.                     self.cleanup(EVENT_PCARD_UNABLE_TO_MOUNT)
  146.                     return
  147.  
  148.                 self.device_uri = self.pc.device.device_uri
  149.                 user_cfg.last_used.device_uri = self.device_uri
  150.  
  151.                 # TODO:
  152.                 #self.pc.device.sendEvent(EVENT_START_PCARD_JOB)
  153.  
  154.                 disk_info = self.pc.info()
  155.                 self.pc.write_protect = disk_info[8]
  156.  
  157.                 if self.pc.write_protect:
  158.                     log.warning("Photo card is write protected.")
  159.  
  160.                 log.info("Photocard on device %s mounted" % self.pc.device_uri)
  161.  
  162.                 if not self.pc.write_protect:
  163.                     log.info("DO NOT REMOVE PHOTO CARD UNTIL YOU EXIT THIS PROGRAM")
  164.  
  165.                 if user_cfg.last_used.working_dir and \
  166.                     os.path.exists(user_cfg.last_used.working_dir):
  167.  
  168.                     self.unload_dir = user_cfg.last_used.working_dir
  169.  
  170.                 try:
  171.                     os.chdir(self.unload_dir)
  172.                 except OSError:
  173.                     self.unload_dir = ''
  174.  
  175.                 self.UnloadDirectoryEdit.setText(self.unload_dir)
  176.  
  177.                 self.unload_list = self.pc.get_unload_list()
  178.  
  179.                 self.total_number = 0
  180.                 self.total_size = 0
  181.  
  182.                 self.updateSelectionStatus()
  183.  
  184.                 if self.pc.write_protect:
  185.                     self.removal_option = 0 # leave all files on card
  186.  
  187.                 # Item map disambiguates between files of the same
  188.                 # name that are on the pcard in more than one location
  189.                 self.item_map = {}
  190.  
  191.                 QApplication.restoreOverrideCursor()
  192.  
  193.         else:
  194.             log.debug("Unsupported device")
  195.             self.y = 0
  196.             self.clear()
  197.             return False
  198.  
  199.         self.busy = False
  200.  
  201.         QTimer.singleShot(0, self.updateIconView)
  202.  
  203.         self.display_update_timer = QTimer(self, "DisplayUpdateTimer")
  204.         self.connect(self.display_update_timer, SIGNAL('timeout()'), self.updateDisplay)
  205.  
  206.         self.display_update_timer.start(1000)
  207.  
  208.         return True
  209.  
  210.  
  211.  
  212.     def addIconList(self):
  213.         widget = self.getWidget()
  214.  
  215.         layout32 = QGridLayout(widget,1,1,5,10,"layout32")
  216.  
  217.         spacer34 = QSpacerItem(20,20,QSizePolicy.Expanding,QSizePolicy.Minimum)
  218.         layout32.addItem(spacer34,2,2)
  219.  
  220.         self.selectAllPushButton = PixmapLabelButton(widget, 'ok.png', None)
  221.  
  222.         layout32.addWidget(self.selectAllPushButton,2,0)
  223.  
  224.         self.ShowThumbnailsButton = PixmapLabelButton(widget, 'thumbnail.png', None)
  225.  
  226.         layout32.addWidget(self.ShowThumbnailsButton,2,3)
  227.  
  228.         self.IconView = QIconView(widget,"IconView")
  229.         self.IconView.setResizePolicy(QIconView.AutoOneFit)
  230.         self.IconView.setSelectionMode(QIconView.Multi)
  231.         self.IconView.setResizeMode(QIconView.Adjust)
  232.         self.IconView.setMaxItemWidth(200)
  233.         self.IconView.setAutoArrange(0)
  234.         self.IconView.setItemsMovable(1)
  235.  
  236.         layout32.addMultiCellWidget(self.IconView,0,0,0,3)
  237.  
  238.         self.selectNonePushButton = PixmapLabelButton(widget, 'folder_remove.png', None)
  239.  
  240.         layout32.addWidget(self.selectNonePushButton,2,1)
  241.  
  242.         self.selectionStatusText = QLabel(widget,"selectionStatusText")
  243.         layout32.addMultiCellWidget(self.selectionStatusText,1,1,0,3)
  244.         self.selectAllPushButton.setText(self.__tr("Select All"))
  245.         self.selectNonePushButton.setText(self.__tr("Select None"))
  246.         self.ShowThumbnailsButton.setText(self.__tr("Show Thumbnails"))
  247.  
  248.         self.connect(self.selectAllPushButton,SIGNAL("clicked()"),self.selectAllPushButton_clicked)
  249.         self.connect(self.selectNonePushButton,SIGNAL("clicked()"),self.selectNonePushButton_clicked)
  250.         self.connect(self.IconView,SIGNAL("doubleClicked(QIconViewItem*)"),self.IconView_doubleClicked)
  251.         self.connect(self.IconView,SIGNAL("rightButtonClicked(QIconViewItem*,const QPoint&)"),self.IconView_rightButtonClicked)
  252.         self.connect(self.ShowThumbnailsButton,SIGNAL("clicked()"),self.ShowThumbnailsButton_clicked)
  253.  
  254.         self.addWidget(widget, "file_list", maximize=True)
  255.  
  256.  
  257.     def selectAllPushButton_clicked(self):
  258.         self.IconView.selectAll(1)
  259.  
  260.     def selectNonePushButton_clicked(self):
  261.         self.IconView.selectAll(0)
  262.  
  263.     def IconView_doubleClicked(self, a0):
  264.         return self.PopupProperties()
  265.  
  266.     def IconView_rightButtonClicked(self, item, pos):
  267.         popup = QPopupMenu(self)
  268.         popup.insertItem(self.__tr("Properties"), self.PopupProperties)
  269.  
  270.         if item is not None and \
  271.             item.mime_type == 'image' and \
  272.             item.mime_subtype == 'jpeg' and \
  273.             self.pc.get_exif_path(item.path) and \
  274.             not item.thumbnail_set:
  275.  
  276.             popup.insertItem(self.__tr("Show Thumbnail"), self.showThumbNail)
  277.  
  278.         popup.popup(pos)
  279.  
  280.     def ShowThumbnailsButton_clicked(self):
  281.         self.ShowThumbnailsButton.setEnabled(False)
  282.         self.updateIconView(first_load=False)
  283.  
  284.     def updateDisplay(self):
  285.         if not self.busy:
  286.             self.total_number = 0
  287.             self.total_size = 0
  288.             i = self.IconView.firstItem()
  289.  
  290.             while i is not None:
  291.  
  292.                 if i.isSelected():
  293.                     self.total_number += 1
  294.                     self.total_size += i.size
  295.  
  296.                 i = i.nextItem()
  297.  
  298.             self.updateSelectionStatus()
  299.  
  300.         self.updateUnloadButton()
  301.  
  302.     def updateUnloadButton(self):
  303.         self.unloadButton.setEnabled(not self.busy and self.total_number and os.path.exists(self.unload_dir))
  304.         #qApp.processEvents()
  305.  
  306.     def updateSelectionStatus(self):
  307.         if self.total_number == 0:
  308.             s = self.__tr("No files selected")
  309.  
  310.         elif self.total_number == 1:
  311.             s = self.__tr("1 file selected, %1").arg(utils.format_bytes(self.total_size, True))
  312.  
  313.         else:
  314.             s = self.__tr("%1 files selected, %2").arg(self.total_number).arg(utils.format_bytes(self.total_size, True))
  315.  
  316.         self.selectionStatusText.setText(s)
  317.  
  318.  
  319.     def PopupDisplay(self):
  320.         self.Display(self.IconView.currentItem())
  321.  
  322.     def PopupProperties(self):
  323.         self.Properties(self.IconView.currentItem())
  324.  
  325.     def showThumbNail(self):
  326.         item = self.IconView.currentItem()
  327.         exif_info = self.pc.get_exif_path(item.path)
  328.  
  329.         if len(exif_info) > 0:
  330.             if 'JPEGThumbnail' in exif_info:
  331.                 pixmap = QPixmap()
  332.                 pixmap.loadFromData(exif_info['JPEGThumbnail'], "JPEG")
  333.                 self.resizePixmap(pixmap)
  334.                 del exif_info['JPEGThumbnail']
  335.                 item.setPixmap(pixmap)
  336.  
  337.                 self.IconView.adjustItems()
  338.  
  339.         else:
  340.             self.form.FailureUI(self.__tr("<p><b>No thumbnail found in image.</b>"))
  341.  
  342.         item.thumbnail_set = True
  343.  
  344.     def Properties(self, item):
  345.         if item is not None:
  346.             if not item.exif_info:
  347.                 item.exif_info = self.pc.get_exif_path(item.path)
  348.  
  349.             ImagePropertiesDlg(item.filename, item.dirname,
  350.                                 '/'.join([item.mime_type, item.mime_subtype]),
  351.                                 utils.format_bytes(item.size, True),
  352.                                 item.exif_info, self).exec_loop()
  353.  
  354.  
  355.     def updateIconView(self, first_load=True):
  356.         QApplication.setOverrideCursor(QApplication.waitCursor)
  357.         self.busy = True
  358.         self.first_load = first_load
  359.         self.item_num = 0
  360.  
  361.         if first_load:
  362.             self.IconView.clear()
  363.  
  364.         self.num_items = len(self.unload_list)
  365.  
  366.         self.progress_dlg = QProgressDialog(self.__tr("Loading..."), \
  367.             self.__tr("Cancel"), self.num_items, self, "progress", 0)
  368.         self.progress_dlg.setCaption(self.__tr("HP Device Manager"))
  369.  
  370.         self.progress_dlg.setMinimumDuration(0)
  371.         self.progress_dlg.setProgress(0)
  372.  
  373.         self.load_timer = QTimer(self, "LoadTimer")
  374.         self.connect(self.load_timer, SIGNAL('timeout()'), self.continueLoadIconView)
  375.         self.load_timer.start(0)
  376.  
  377.  
  378.     def continueLoadIconView(self):
  379.         if self.item_num == self.num_items:
  380.             self.load_timer.stop()
  381.             self.disconnect(self.load_timer, SIGNAL('timeout()'), self.continueLoadIconView)
  382.             self.load_timer = None
  383.             del self.load_timer
  384.  
  385.             self.progress_dlg.close()
  386.             self.progress_dlg = None
  387.  
  388.             self.IconView.adjustItems()
  389.             self.busy = False
  390.             QApplication.restoreOverrideCursor()
  391.             return
  392.  
  393.         self.progress_dlg.setProgress(self.item_num)
  394.  
  395.         f = self.unload_list[self.item_num]
  396.         self.item_num += 1
  397.         log.debug(f)
  398.  
  399.         path, size = f[0], f[1]
  400.  
  401.         typ, subtyp = self.pc.classify_file(path).split('/')
  402.  
  403.         if not self.first_load and typ == 'image' and subtyp == 'jpeg':
  404.  
  405.             exif_info = self.pc.get_exif_path(path)
  406.             if len(exif_info) > 0:
  407.  
  408.                 if 'JPEGThumbnail' in exif_info:
  409.                     pixmap = QPixmap()
  410.                     pixmap.loadFromData(exif_info['JPEGThumbnail'], "JPEG")
  411.  
  412.                     self.resizePixmap(pixmap)
  413.  
  414.                     del exif_info['JPEGThumbnail']
  415.                     dname, fname=os.path.split(path)
  416.                     x = self.item_map[fname]
  417.  
  418.                     if len(x) == 1:
  419.                         item = self.IconView.findItem(fname, 0)
  420.                     else:
  421.                         i = x.index(path)
  422.                         if i == 0:
  423.                             item = self.IconView.findItem(fname, 0)
  424.                         else:
  425.                             item = self.IconView.findItem(fname + " (%d)" % (i+1), 0)
  426.  
  427.                     if item is not None:
  428.                         item.setPixmap(pixmap)
  429.                         item.thumbnail_set = True
  430.  
  431.                     return
  432.  
  433.         elif self.first_load:
  434.             if typ == 'image':
  435.                 f = self.image_icon_map.get(subtyp, 'unknown')
  436.             
  437.             elif typ == 'video':
  438.                 f = self.video_icon_map.get(subtyp, 'movie')
  439.             
  440.             elif typ == 'audio':
  441.                 f = 'sound'
  442.             
  443.             else:
  444.                 f = 'unknown'
  445.  
  446.             dirname, fname=os.path.split(path)
  447.             num = 1
  448.             try:
  449.                 self.item_map[fname]
  450.             except:
  451.                 self.item_map[fname] = [path]
  452.             else:
  453.                 self.item_map[fname].append(path)
  454.                 num = len(self.item_map[fname])
  455.  
  456.             if num == 1:
  457.                 IconViewItem(self.IconView, dirname, fname, path, 
  458.                     load_pixmap(f, '128x128'), typ, subtyp, size)
  459.             else:
  460.                 IconViewItem(self.IconView, dirname, fname + " (%d)" % num,
  461.                               path,load_pixmap(f, '128x128'), typ, subtyp, size)
  462.  
  463.     def resizePixmap(self, pixmap):
  464.         w, h = pixmap.width(), pixmap.height()
  465.  
  466.         if h > 128 or w > 128:
  467.             ww, hh = w - 128, h - 128
  468.             if ww >= hh:
  469.                 pixmap.resize(128, int(float((w-ww))/w*h))
  470.             else:
  471.                 pixmap.resize(int(float((h-hh))/h*w), 128)
  472.  
  473.     def addFolder(self):
  474.         widget = self.getWidget()
  475.         layout38 = QGridLayout(widget,1,1,5,10,"layout38")
  476.  
  477.         self.UnloadDirectoryEdit = QLineEdit(widget,"UnloadDirectoryEdit")
  478.         layout38.addWidget(self.UnloadDirectoryEdit,0,0)
  479.  
  480.         self.UnloadDirectoryBrowseButton = PixmapLabelButton(widget, 'folder_open.png', None)
  481.         layout38.addWidget(self.UnloadDirectoryBrowseButton,0,1)
  482.  
  483.         self.UnloadDirectoryBrowseButton.setText(self.__tr("Browse..."))
  484.         self.connect(self.UnloadDirectoryBrowseButton,SIGNAL("clicked()"),self.UnloadDirectoryBrowseButton_clicked)
  485.         self.connect(self.UnloadDirectoryEdit,SIGNAL("textChanged(const QString&)"),self.UnloadDirectoryEdit_textChanged)        
  486.  
  487.         self.bg = self.UnloadDirectoryEdit.paletteBackgroundColor()
  488.  
  489.         self.addWidget(widget, "folder")
  490.  
  491.     def UnloadDirectoryEdit_textChanged(self, dir):
  492.         self.unload_dir = unicode(dir)
  493.  
  494.         if not os.path.exists(self.unload_dir):
  495.             self.UnloadDirectoryEdit.setPaletteBackgroundColor(QColor(0xff, 0x99, 0x99))
  496.         else:
  497.             self.UnloadDirectoryEdit.setPaletteBackgroundColor(self.bg)
  498.  
  499.     def UnloadDirectoryBrowseButton_clicked(self):
  500.         old_dir = self.unload_dir
  501.         self.unload_dir = unicode(QFileDialog.getExistingDirectory(self.unload_dir, self))
  502.  
  503.         if not len(self.unload_dir):
  504.             return
  505.  
  506.         elif not utils.is_path_writable(self.unload_dir):
  507.             self.form.FailureUI(self.__tr("<p><b>The unload directory path you entered is not valid.</b><p>The directory must exist and you must have write permissions."))
  508.             self.unload_dir = old_dir
  509.  
  510.         else:
  511.             self.UnloadDirectoryEdit.setText(self.unload_dir)
  512.             os.chdir(self.unload_dir)
  513.             user_cfg.last_used.working_dir = self.unload_dir.encode('utf-8')
  514.  
  515.     def addOptions(self):
  516.         widget = self.getWidget()
  517.  
  518.         layout34 = QHBoxLayout(widget,5,10,"layout34")
  519.  
  520.         self.textLabel5_4 = QLabel(widget,"textLabel5_4")
  521.         layout34.addWidget(self.textLabel5_4)
  522.         spacer20_4 = QSpacerItem(20,20,QSizePolicy.Expanding,QSizePolicy.Minimum)
  523.         layout34.addItem(spacer20_4)
  524.  
  525.         self.optionComboBox = QComboBox(0,widget,"optionsComboBox")
  526.         layout34.addWidget(self.optionComboBox)
  527.  
  528.         self.textLabel5_4.setText(self.__tr("File removal:"))
  529.         self.optionComboBox.clear()
  530.         self.optionComboBox.insertItem(self.__tr("Leave unloaded files on photo card")) # 0
  531.         self.optionComboBox.insertItem(self.__tr("Remove all unloaded files from photo card")) # 1
  532.         self.optionComboBox.setCurrentItem(self.removal_option)
  533.  
  534.         self.connect(self.optionComboBox, SIGNAL("activated(int)"), self.optionComboBox_activated)
  535.  
  536.         self.addWidget(widget, "option")
  537.  
  538.     def optionComboBox_activated(self, i):
  539.         self.removal_option = i
  540.  
  541.  
  542.     def unloadButton_clicked(self):
  543.         was_cancelled = False
  544.         self.busy = True
  545.         self.unloadButton.setEnabled(False)
  546.         self.unload_dir = unicode(self.UnloadDirectoryEdit.text())
  547.         dir_error = False
  548.  
  549.         try:
  550.             try:
  551.                 os.chdir(self.unload_dir)
  552.             except OSError:
  553.                 log.error("Directory not found: %s" % self.unload_dir)
  554.                 dir_error = True
  555.  
  556.             if dir_error or not utils.is_path_writable(self.unload_dir):
  557.                 self.form.FailureUI(self.__tr("<p><b>The unload directory path is not valid.</b><p>Please enter a new path and try again."))
  558.                 return
  559.  
  560.             unload_list = []
  561.             i = self.IconView.firstItem()
  562.             self.total_size = 0
  563.             while i is not None:
  564.  
  565.                 if i.isSelected():
  566.                     unload_list.append((i.path, i.size, i.mime_type, i.mime_subtype))
  567.                     self.total_size += i.size
  568.                 i = i.nextItem()
  569.  
  570.             if self.total_size == 0:
  571.                 self.form.FailureUI(self.__tr("<p><b>No files are selected to unload.</b><p>Please select one or more files to unload and try again."))
  572.                 return
  573.  
  574.             self.total_complete = 0
  575.             self.progress_dlg = QProgressDialog(self.__tr("Unloading card..."), \
  576.                 self.__tr("Cancel"), 100, self, "progress", 1)
  577.             self.progress_dlg.setCaption(self.__tr("HP Device Manager"))
  578.             self.progress_dlg.setMinimumDuration(0)
  579.             self.progress_dlg.setProgress(0)
  580.             qApp.processEvents()
  581.  
  582.             if self.removal_option == 0: # Leave files
  583.                 total_size, total_time, was_cancelled = \
  584.                     self.pc.unload(unload_list, self.updateStatusProgressBar, None, True)
  585.  
  586.             elif self.removal_option == 1: # remove selected
  587.                 total_size, total_time, was_cancelled = \
  588.                     self.pc.unload(unload_list, self.updateStatusProgressBar, None, False)
  589.  
  590.             else: # remove all
  591.                 total_size, total_time, was_cancelled = \
  592.                     self.pc.unload(unload_list, self.updateStatusProgressBar, None, False)
  593.                 # TODO: Remove remainder of files
  594.  
  595.             self.progress_dlg.close()
  596.             self.progress_dlg = None
  597.  
  598.             # TODO:
  599.             #self.pc.device.sendEvent(EVENT_PCARD_FILES_TRANSFERED)
  600.  
  601.             if self.removal_option != 0: # remove selected or remove all
  602.                 self.unload_list = self.pc.get_unload_list()
  603.                 self.total_number = 0
  604.                 self.total_size = 0
  605.                 self.item_map = {}
  606.                 self.total_complete = 0
  607.                 self.updateIconView()
  608.  
  609.             if was_cancelled:
  610.                 self.form.FailureUI(self.__tr("<b>Unload cancelled at user request.</b>"))
  611.             else:
  612.                 pass
  613.  
  614.         finally:
  615.             self.busy = False
  616.  
  617.     def updateStatusProgressBar(self, src, trg, size):
  618.         qApp.processEvents()
  619.         self.total_complete += size
  620.         percent = int(100.0 * self.total_complete/self.total_size)
  621.         self.progress_dlg.setProgress(percent)
  622.         qApp.processEvents()
  623.  
  624.         if self.progress_dlg.wasCanceled():
  625.             return True
  626.  
  627.         return False
  628.  
  629.  
  630.     def cleanup(self, error=0):
  631.         if self.pc is not None:
  632.             if error > 0:
  633.                 # TODO:
  634.                 #self.pc.device.sendEvent(error, typ='error')
  635.                 pass
  636.  
  637.             try:
  638.                 self.pc.umount()
  639.                 self.pc.device.close()
  640.             except Error:
  641.                 pass
  642.  
  643.     def funcButton_clicked(self):
  644.         if self.pc is not None:
  645.             self.pc.umount()
  646.             self.pc.device.close()
  647.         
  648.         self.form.close()
  649.  
  650.     def __tr(self,s,c = None):
  651.         return qApp.translate("ScrollUnloadView",s,c)
  652.